package ui.control
{
	import flash.display.Sprite;
	
	import texture.BitmapEx;

	/**
	 * 进度条
	 * @author weiping
	 * 
	 */
	public class GuiProgressBar extends GuiStatic
	{
		private var backImg:BitmapEx;// 背景
		private var progressImg:BitmapEx;//进度条
		private var maskBack:Sprite;
		private var pirogressValue:Number;
		
		public function GuiProgressBar(back:BitmapEx, pro:BitmapEx, offsetX:int, offsetY:int)
		{
			super();
			
			pirogressValue = 0;
			textField.multiline = false;
			
			backImg = back;
			addChildAt(backImg,0);
			progressImg = pro;
			
			progressImg.x = offsetX;
			progressImg.y = offsetY;
			addChildAt(progressImg,1);
			
			maskBack = new Sprite();
			maskBack.x = progressImg.x;
			maskBack.y = progressImg.y;
			drawMask();
			
			addChildAt(maskBack,2);
			progressImg.mask = maskBack;
			
			this.textField.multiline = false;
			this.textField.wordWrap = false;
			
			
			this.mouseChildren = false;

		}

		public function get progress():Number
		{
			return pirogressValue;
		}

		public function set progress(value:Number):void
		{
			pirogressValue = value;
			updataProgress(value);
		}
		
		private function updataProgress(value:Number):void
		{
			maskBack.scaleX = value;
		}

		private function drawMask():void
		{
			maskBack.graphics.clear();
			maskBack.graphics.beginFill(0xffffff);
			maskBack.graphics.drawRect(0, 0, progressImg.width, progressImg.height);
			maskBack.graphics.endFill();
			maskBack.scaleX = pirogressValue;
		}


	}
}